/*
+--------------------------
| FreeloaderOS v0.0.1
|  - Microkernel
+--------------------------
| Written by Alec Hussey
| Copyright (c) 2007
|  - Deus X Foundation
+---------------------------
*/

/*
 * Programmable Interval Timer
 * aka System Clock
 */

#include <sys/system.h>

int timer_ticks = 0;

/*
Handles the actual timer
*/
void timer_handler(struct regs *r)
{
	timer_ticks++;
	
	/* For every 18 clocks (approx 1 sec)
	 we will display a message to the screen
	if (timer_ticks % 18 == 0)
		putstr("One second has passed.\n");*/
}

/*
Will loop until given time
is reached.
*/
void timer_wait(int ticks)
{
	unsigned long eticks;
	
	eticks = timer_ticks + ticks;
	while (timer_ticks < eticks);
}

/*
Install the system clock by putting
the timer handler into IRQ0.
*/
void init_timer()
{
	irq_install_handler(0, timer_handler);
}
